#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e6 + 10;
int n;
ll a[N];
ll sum = 0;
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    
    int left = 1, right = 1;
    ll k = 0, ret = 0;
    while(right <= n)
    {
        k += a[right];
        while(2 * k >= sum)
        {
            ret = max(ret, sum - k);
            k -= a[left++];
        }
        ret = max(ret, k);
        right++;
    }
    cout << ret << endl;
    return 0;
}
